<?php session_start();?>
<?php require_once('Connections/database.php'); ?>
<?php
if(!isset($_SESSION['user']))
{
	header("Location: login.php");	
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_database, $database);
$query_DanhMuc = "SELECT * FROM danhmuc WHERE Xoa = false";
$DanhMuc = mysql_query($query_DanhMuc, $database) or die(mysql_error());
$row_DanhMuc = mysql_fetch_assoc($DanhMuc);
$totalRows_DanhMuc = mysql_num_rows($DanhMuc);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi-vn" lang="vi-vn">
<head>
    <title>Admin</title>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link href="Content/style.css" rel="stylesheet" type="text/css" />
    <link href="Content/jquery-ui-1.9.2.custom.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui-1.9.2.custom.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery.validate.min.js" type="text/javascript"></script>
    <script src="Scripts/ckeditor/ckeditor.js" type="text/javascript"></script>
    <script src="Scripts/ckeditor/samples/sample.js"></script>
	<script type="text/javascript" src="Editor/scripts/innovaeditor.js"></script>
	
    <script type="text/javascript">
        $(document).ready(function () {
            $('.dropdown').hover(function () {
                $(this).find('.sub_navigation').toggle();
            });
        });

        function MenuClick(url) {
            window.location.href = url;
        }
    </script>
   <script type="text/javascript">
    $(document).ready(function () {
        $("#MenuDanhMuc").removeClass("dropdown").addClass("active");
    });
</script>
</head>
<body>
    <div id="wrap">
        <div id="header">
            <img alt="dat nuoc viet logo" src="Content/Images/gift_logo_20.png" height="100px"/>
        </div>
        <div id="menu">
            <ul id="navigation">
                <li class="dropdown" id="MenuHome"><a href="index.php" class="menuitem">Trang chủ</a></li>
                <li class="dropdown" id="MenuDanhMuc"><a href="DanhMuc.php" class="menuitem">Danh mục</a>
                </li>
                <li class="dropdown" id="MenuSanPham"><a href="SanPham.php" class="menuitem">Sản phẩm</a>
                </li>
                <li class="dropdown" id="MenuCP"><a href="thaydoimatkhau.php" class="menuitem">Thay đổi mật khẩu</a></li>
            </ul>
        </div>

        <div id="date">
            <div class="datecontrol">
                <a href="../index.php" target="_blank">Trang chủ</a>&nbsp;&nbsp;&nbsp;
                <a href="logout.php">Đăng xuất</a>
            </div>
            <div class="clear">&nbsp;</div>
        </div>
        <div id="content">
			<div class="contenttitle">
                <div class="titleplace">
                    <span>Danh mục sản phẩm</span>&nbsp;&nbsp;&nbsp;
                </div>
                <div class="buttonplace">
                    <a href="DanhMuc_addnew.php">
                        <input type="button" value="Thêm danh mục sản phẩm" />
                    </a>
                </div>
                <div class="clear">&nbsp;</div>
            </div>
            <div class="contentitem">
                <table class="tablecontent">
                    <thead>
                        <tr>
                            <th style="width:50px;">&nbsp;
                                
                            </th>
                            <th>
                                Loại sản phẩm
                            </th>
                            <th style="width:120px;text-align:center;">
                                Thứ tự sắp xếp
                            </th>
                            <th style="width:70px">&nbsp;
                                
                            </th>
                        </tr>            
                    </thead>
                    <tbody id="tablecontent">
                    	<?php for($i = 0; $i < $totalRows_DanhMuc; $i++) {?>
                        <tr class="<?php if($i%2===0) {echo 'event';} else {echo 'odd';}?>">
                            <td>
                                <?php echo $row_DanhMuc['idDanhMuc']; ?>
                            </td>
                            <td>
                                <?php echo $row_DanhMuc['TenDanhMuc']; ?>
                            </td>
                            <td style="text-align:center;">
                                <?php echo $row_DanhMuc['ThuTu']; ?>
                            </td>
                            <td>
                                <a href="DanhMuc_edit.php?id=<?php echo $row_DanhMuc['idDanhMuc'];?>">Sửa</a> | 
                                <a href="DanhMuc_edit.php?xoa=<?php echo $row_DanhMuc['idDanhMuc'];?>">Xóa</a>
                            </td>
                        </tr>
                        <?php $row_DanhMuc = mysql_fetch_assoc($DanhMuc);} ?>
                    </tbody>
                </table>    
            </div>

        </div>      
    </div>  
</body>
</html>
<?php
mysql_free_result($DanhMuc);
?>
